#pragma once

#include "../Math/Vec2i.h"
#include <libtcod/libtcod.hpp>
#include <memory>
#include <vector>

typedef std::shared_ptr<TCODHeightMap> TCODHeightMapPtr;
typedef std::shared_ptr<TCODNoise> TCODNoisePtr;
typedef std::shared_ptr<TCODRandom> TCODRandomPtr;


class Cell;
typedef std::shared_ptr<Cell> CellPtr;

class Chunk;
typedef std::shared_ptr<Chunk> ChunkPtr;

class Chunk
{
public:
	Chunk(const Vec2i &viewport, const Vec2i &pos);
	~Chunk();

	void render();

	const Vec2i &getPos() const { return pos; }
	const Vec2i &getLowerBounds() const { return lower_bounds; }
	const Vec2i &getUpperBounds() const { return upper_bounds; }
	const Vec2i &getSize() const { return chunk_size; }
	const CellPtr &getCell(Vec2i pos) const;

	void generate(const TCODNoisePtr &world_noise, const TCODRandomPtr &world_ran, float mountain_height, float hill_height, float land_height, int *smooth_dx, int *smooth_dy, float *smooth_weights);
	bool isGenerated() const { return generated; }

private:
	std::vector<CellPtr> cells;

	Vec2i pos;
	Vec2i lower_bounds;
	Vec2i upper_bounds;

	Vec2i chunk_size;
	TCODHeightMapPtr height_map;
	bool generated;
};
